<?php

// $Id$

require_once($WSC->get_site_inc_dir().'modules/tangra_cms/classes/ci/tcms_ci_dbc.class.php');
require_once($WSC->get_site_inc_dir().'modules/tangra_cms/classes/ci/tcms_ci_type_dbc.class.php');


class TCMS_CI_Composite_DBC extends Tangra_Class {
	private $ci;
	private $ci_specific;
	private $hidden_inc_dir;

	function __construct($hidden_inc_dir) {
		$this->hidden_inc_dir = $hidden_inc_dir;
	}


	public function load_by_id(DB_Connection $dbc, $id) {
		tangra_if_not_int_throw_e($id);

		$ret = false;

		$ci = new TCMS_CI_DBC();
		if ($ci->load_by_id($dbc, $id)) {
			$this->ci = $ci;

			$type = new TCMS_CI_Type_DBC();
			if ($type->load_by_id($dbc, $ci->get_type())) {
				$class_name = $type->get_class_name();
				if (!class_exists($class_name)) {
					require_once($this->hidden_inc_dir.$type->get_class_path());
				}

				$ci_specific = new $class_name;
				$ci_specific->load_by_id($dbc, $id);

				$this->ci_specific = $ci_specific;
				$ret = $id;
			}
		}

		return $ret;
	}


	public function get_as_short_plain_text() {
		return $this->ci_specific->get_as_short_plain_text();
	}


	public function get_as_plain_text() {
		return $this->ci_specific->get_as_plain_text();
	}
}